﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;

namespace SolutionExtender.Controls
{
    public partial class ExportControl : UserControl
    {
        private readonly XmlDocument _settingsDoc;

        public ExportControl(XmlDocument settingDoc)
        {
            InitializeComponent();

            _settingsDoc = settingDoc;
        }

        private void ExportControlLoad(object sender, EventArgs e)
        {
            using(var sfd = new SaveFileDialog())
            {
                sfd.Title = "Select a path where to save the file";
                sfd.Filter = "XML file (*.xml)|*.xml";
                
                if(DialogResult.OK == sfd.ShowDialog())
                {
                    _settingsDoc.Save(sfd.FileName);

                    linkLabel1.Text = sfd.FileName;

                    pnlCompleted.Visible = true;
                    pnlCanceled.Visible = false;
                }
                else
                {
                    pnlCompleted.Visible = false;
                    pnlCanceled.Visible = true;
                }
            }
        }

        private void PictureBox1Click(object sender, EventArgs e)
        {
            Process.Start("http://mscrmtools.blogspot.com");
        }

        private void PictureBox2Click(object sender, EventArgs e)
        {
            Process.Start("http://www.javista.com");
        }

        private void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(linkLabel1.Text);
        }
    }
}
